home *** CD-ROM | disk | FTP | other *** search
- /*
- * inv.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * INV (Image inversion)
- *
- * Inverts the input image and places the resulting
- * image in the output file
- */
-
- #include "inv.h"
-
-
- #define ON 1
- #define OFF 0
-
- /*
- * global variables
- */
- extern char *optarg;
- extern int optind, opterr;
- extern short tiffInput; /* flag=0 if no ImageIn to set tags; else =1 */
-
-
- /*
- * usage of routine
- */
- void
- usage (char *progname)
- {
- progname = last_bs (progname);
- printf ("USAGE: %s inimg outimg [-L]\n", progname);
- printf ("\n%s inverts the input image and writes the resulting\n", progname);
- printf ("image to the specified output file.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" inimg: input image filename (TIF)\n");
- printf (" outimg: ouput image filename (TIF)\n\n");
- printf ("OPTIONS:\n");
- printf (" -L: print Software License for this module\n");
- exit (1);
- }
-
- void
- inv_image (Image * imgIn)
- {
- int ix, iy;
- int max_x, max_y;
-
- max_y = ImageGetHeight (imgIn);
- max_x = ImageGetWidth (imgIn);
- for (ix = 0; ix < max_x; ix++)
- for (iy = 0; iy < max_y; iy++) {
- setpixel (ix, iy, imgIn, (int) (~getpixel (ix, iy, imgIn)));
- }
- }
-
- void
- main (int argc, char *argv[])
- {
- Image *imgIn;
-
- int i_arg;
-
- /*
- * cmd line options
- */
- static char *optstring = "L";
-
-
- /*
- * parse command line
- */
- optind = 3; /* set getopt to point to the 3rd arg */
- opterr = ON; /* give error messages */
-
-
- if (argc < 3)
- usage (argv[0]);
-
- while ((i_arg = getopt (argc, argv, optstring)) != EOF) {
- switch (i_arg) {
- case 'L':
- print_sos_lic ();
- exit (0);
- default:
- printf ("\ngetopt: unknown condition encountered\n");
- exit (1);
- break;
- }
- }
-
- /*
- * Read input image
- */
- imgIn = ImageIn (argv[1]);
-
- if (imgIn->bps == 8 && imgIn->spp == 3) {
- printf ("Got RGB image!!!\nInput image must be Grayscale or B&W!!\n");
- exit (1);
- }
-
- /*
- * perform image inversion
- */
- inv_image (imgIn);
-
- /*
- * reset tiffInput so that we write a grayscale file (i.e tags are not copied)
- */
- tiffInput = 0;
-
- /*
- * Write the output image
- */
- ImageOut (argv[2], imgIn);
- }
-